package com.lin.baby.boot.chapter3.config;

import com.lin.baby.boot.chapter1.service.HelloService;
import com.lin.baby.boot.chapter1.service.impl.HelloServiceImpl;
import com.lin.baby.boot.chapter3.service.HelloWordService;
import com.lin.baby.boot.chapter3.service.impl.HelloWordByCnServiceImpl;
import com.lin.baby.boot.chapter3.service.impl.HelloWordServiceImpl;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.*;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 应用全局配置
 *
 * @author WangYang
 * @version 1.0
 * @datetime 2016/10/13 16:26
 */
@Configuration
@ComponentScan({"com.lin.baby.boot.chapter1.service.*", "com.lin.baby.boot.chapter3.*"})
@PropertySource("classpath:properties/settings.properties")
@Service("elConfig")
public class ApplicationResourceConfig {

    @Resource
    private Environment environment;

    @Value("#{systemProperties['os.name']}")
    private String osName;

    @Value("${system.name}")
    private String systemName;

    @Value("#{T(java.lang.Math).random() * 100.0}")
    private double randomNumber;

    @Value("#{common.title}")
    private String title;

    // 必须获取PropertySourcesPlaceholderConfigurer，否则属性上用@Value获取不到配置文件中的值
    @Bean
    public static PropertySourcesPlaceholderConfigurer propertyConfigure() {
        return new PropertySourcesPlaceholderConfigurer();
    }
    public Environment getEnvironment() {
        return environment;
    }

    public void setEnvironment(Environment environment) {
        this.environment = environment;
    }

    public String getOsName() {
        return osName;
    }

    public void setOsName(String osName) {
        this.osName = osName;
    }

    public String getSystemName() {
        return systemName;
    }

    public void setSystemName(String systemName) {
        this.systemName = systemName;
    }

    public double getRandomNumber() {
        return randomNumber;
    }

    public void setRandomNumber(double randomNumber) {
        this.randomNumber = randomNumber;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }
}
